package com.ruoyi.carbon.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.carbon.domain.ScmSaleCustomer;
import com.ruoyi.carbon.service.IScmSaleCustomerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户档案Controller
 * 
 * @author ruoyi
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/carbon/customer")
public class ScmSaleCustomerController extends BaseController
{
    @Autowired
    private IScmSaleCustomerService scmSaleCustomerService;

    /**
     * 查询客户档案列表
     */
    @PreAuthorize("@ss.hasPermi('carbon:customer:list')")
    @GetMapping("/list")
    public AjaxResult list(ScmSaleCustomer scmSaleCustomer)
    {

        List<ScmSaleCustomer> list = scmSaleCustomerService.selectScmSaleCustomerList(scmSaleCustomer);
        return AjaxResult.success(list);
    }

    /**
     * 导出客户档案列表
     */
    @PreAuthorize("@ss.hasPermi('carbon:customer:export')")
    @Log(title = "客户档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmSaleCustomer scmSaleCustomer)
    {
        List<ScmSaleCustomer> list = scmSaleCustomerService.selectScmSaleCustomerList(scmSaleCustomer);
        ExcelUtil<ScmSaleCustomer> util = new ExcelUtil<ScmSaleCustomer>(ScmSaleCustomer.class);
        util.exportExcel(response, list, "客户档案数据");
    }

    /**
     * 获取客户档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('carbon:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scmSaleCustomerService.selectScmSaleCustomerById(id));
    }

    /**
     * 新增客户档案
     */
    @PreAuthorize("@ss.hasPermi('carbon:customer:add')")
    @Log(title = "客户档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmSaleCustomer scmSaleCustomer)
    {
        return toAjax(scmSaleCustomerService.insertScmSaleCustomer(scmSaleCustomer));
    }

    /**
     * 修改客户档案
     */
    @PreAuthorize("@ss.hasPermi('carbon:customer:edit')")
    @Log(title = "客户档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmSaleCustomer scmSaleCustomer)
    {
        return toAjax(scmSaleCustomerService.updateScmSaleCustomer(scmSaleCustomer));
    }

    /**
     * 删除客户档案
     */
    @PreAuthorize("@ss.hasPermi('carbon:customer:remove')")
    @Log(title = "客户档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scmSaleCustomerService.deleteScmSaleCustomerByIds(ids));
    }
}
